<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  version="1.0" >

<!-- rule for the whole document: root element is page -->

<xsl:template match="base">
  
    <xsl:apply-templates select="title"/>
 
</xsl:template>

<!-- A series of XSLT rules that produce fo:blocks to be inserted above -->

 <xsl:template match="base/title">
    <store>

    <menus>
    <xsl:apply-templates select="../menu"/>
</menus>    

	<products>
    <xsl:apply-templates select="../pizza"/>
    
    <xsl:apply-templates select="../ingredientBase"/>
    <xsl:apply-templates select="../boisson"/>
    </products>

	</store>

  </xsl:template>
  
  <xsl:template match="ingredientBase">
<ingredient>
    <name><xsl:value-of select="@name"/></name>
    <stock><xsl:value-of select="@stock"/></stock>
    <price><xsl:text>-1</xsl:text></price>
</ingredient>
  </xsl:template>

 <xsl:template match="pizza">
<xsl:element name="pizza">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
    <name><xsl:value-of select="@name"/></name>
    <stock><xsl:text>-1</xsl:text></stock>
    <price><xsl:value-of select="@price"/></price>
    
   <ingredients>
    <xsl:for-each select="ingredient">
         <xsl:apply-templates select="."/>
    </xsl:for-each>
</ingredients>
</xsl:element>
    
  </xsl:template>
  
  <xsl:template match="boisson">
<xsl:element name="boisson">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>

    <name><xsl:value-of select="@name"/></name>
	<price><xsl:value-of select="@price"/></price>
<stock>-1</stock>
</xsl:element>
  </xsl:template>


  <xsl:template match="menu">
<xsl:element name="menu">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
    <name><xsl:value-of select="@name"/></name>
    <description><xsl:value-of select="@description"/></description>
    <stock>-1</stock>
    <price><xsl:value-of select="@price"/></price>
    <products></products>
</xsl:element>
  </xsl:template>
  

 <xsl:template match="ingredient">
<xsl:element name="ingredient">
<xsl:attribute name="id"><xsl:value-of select="/base/ingredientBase[@name=current()]/@id"/></xsl:attribute>
</xsl:element>
</xsl:template>


</xsl:stylesheet>
